from tkinter import *
from tkinter import filedialog
from tkinter import ttk
from tkinter import font as tkfont
from threading import Thread
from mini_tools.cjjtool import *
from mini_tools.myexcel import *
from mini_tools.mytools import *
from sql import sqlseverDB
from config import *
import tkinter.messagebox as messagebox
import openpyxl,time,concurrent.futures

class AlgQKFra(Frame):
    def __init__(self,master=None):
        Frame.__init__(self,master)
        Label(self, text='阿里狗群控2', fg="black", bg="yellow",font=("微软雅黑", 13)).pack(fill=X,padx=2)
        PolGm(self).pack(fill=X,padx=3,pady=3)
        PolHidePro(self).pack(fill=X,padx=2,pady=2)

class PolGm(Frame):
    def __init__(self,master=None):
        Frame.__init__(self,master)
        self.ms = sqlseverDB('{SQL Server}', SQL_SERVER, 'SuMaiTongPol', SQL_USER, SQL_PWD)
        self.countStr=StringVar()
        self.countStr.set('正在获取发布波兰跟卖店铺数量...')
        self.statusStr=StringVar()
        self.statusStr.set('正在获取发布波兰跟卖任务状态')
        self.taskid=16
        self.createWidgets()
        Thread(target=self.getcount).start()

    def createWidgets(self):

        f1=Frame(self)
        f1.pack(fill=X,padx=2,pady=2)

        Rf1=Frame(f1)
        Rf1.pack(side=RIGHT,fill=Y)
        
        f03=Frame(Rf1)
        f03.pack(fill=X,padx=2)
        Label(f03, text='《发布波兰跟卖》',fg='#6B238E',font=("微软雅黑", 12),anchor="w").pack(side=LEFT,padx=2)

        f00=Frame(Rf1)
        f00.pack(fill=X,padx=2,pady=2)
        Label(f00, textvariable=self.countStr,fg='red').pack(side=LEFT, padx=2, pady=2)
        f02=Frame(Rf1)
        f02.pack(fill=X,padx=2,pady=2)
        Label(f02, textvariable=self.statusStr,fg='red',width=30,anchor="w").pack(side=LEFT, padx=2, pady=2)
        f01=Frame(Rf1)
        f01.pack(fill=X,padx=2,pady=2)
        self.btn_start=Button(f01,text='开启任务',state=DISABLED,command=lambda:Thread(target=self.start_task).start(),fg='#ffffff',bg='green',width=15)
        self.btn_start.pack(side=LEFT,padx=2, pady=2)

        lf1=Frame(f1)
        lf1.pack(side=LEFT,fill=Y)
        PolCJLL(lf1).pack()

        lf2=Frame(f1)
        lf2.pack(side=LEFT,fill=Y)
        PolDwonBG(lf2).pack(padx=40)

        f2=Frame(self)
        f2.pack(fill=X,padx=2,pady=2)

        Lf21=Frame(f2)
        Lf21.pack(side=LEFT,fill=Y)
        PolEndPro(Lf21).pack()

        Lf22=Frame(f2)
        Lf22.pack(side=LEFT,fill=Y)
        PolRelistPro(Lf22).pack(padx=35)

        Rf21=Frame(f2)
        Rf21.pack(side=RIGHT,fill=Y)
        PolCJPay(Rf21).pack()


    def getcount(self):
        while True:
            try:
                sqlstr1='select count(*) from houtai_alg where isupload=1'
                rs1=self.ms.ExecQuery(sqlstr1)
                self.countStr.set(f'店铺一共 {rs1[0][0]} 个')
                sqlstr2='select [state],[tcount] from task where [id]=?'
                rs2=self.ms.ExecQuery(sqlstr2,(self.taskid,))
                rwstatus,rwcount=rs2[0]
                if rwstatus==0:
                    self.statusStr.set('任务未开启')
                    self.btn_start.config(state=NORMAL)
                else:
                    self.statusStr.set(f'任务进行中,队列数剩余:{rwcount}')
                    self.btn_start.config(state=DISABLED)

            except Exception as e:
                pass
            time.sleep(5)
    
    def start_task(self):

        if not messagebox.askyesno('提示','确定开启发布波兰跟卖任务?'):
            return
        
        self.btn_start.config(state=DISABLED)
        sqlstr1='select count(*) from houtai_alg where isupload=1'
        rs1=self.ms.ExecQuery(sqlstr1)
        dpcount=rs1[0][0]
        self.countStr.set(f'发布波兰跟卖店铺一共 {dpcount} 个')
        
        aff1=self.ms.ExecNoQuery('update [task] set state=1,tcount=? where [id]=?',(dpcount,self.taskid))
        if aff1:
            print(f'开启任务成功,开始 {dpcount} 个发布波兰跟卖')

        else:
            print('开启任务失败')
            messagebox.showerror('提示','开启任务失败')
        
        self.btn_start.config(state=NORMAL)

class PolDwonBG(Frame):
    def __init__(self,master=None):
        Frame.__init__(self,master)
        self.ms = sqlseverDB('{SQL Server}', SQL_SERVER, 'SuMaiTongPol', SQL_USER, SQL_PWD)
        self.countStr=StringVar()
        self.countStr.set('正在获取下载波兰跟卖报告店铺数量...')
        self.statusStr=StringVar()
        self.statusStr.set('正在获取下载波兰跟卖报告表任务状态')
        self.taskid=19
        self.createWidgets()
        Thread(target=self.getcount).start()

    def createWidgets(self):

        f1=Frame(self)
        f1.pack(fill=X,padx=2,pady=2)

        Lf=Frame(f1)
        Lf.pack(side=LEFT,fill=Y)

        f03=Frame(Lf)
        f03.pack(fill=X,padx=2)
        Label(f03, text='《下载波兰跟卖报告》',fg='#6B238E',font=("微软雅黑", 12),anchor="w").pack(side=LEFT,padx=2)


        f00=Frame(Lf)
        f00.pack(fill=X,padx=2,pady=2)
        Label(f00, textvariable=self.countStr,fg='red').pack(side=LEFT, padx=2, pady=2)
        f02=Frame(Lf)
        f02.pack(fill=X,padx=2,pady=2)
        Label(f02, textvariable=self.statusStr,fg='red',width=30,anchor="w").pack(side=LEFT, padx=2, pady=2)
        f01=Frame(Lf)
        f01.pack(fill=X,padx=2,pady=2)
        self.btn_start=Button(f01,text='开启任务',state=DISABLED,command=lambda:Thread(target=self.start_task).start(),fg='#ffffff',bg='green',width=15)
        self.btn_start.pack(side=LEFT,padx=2, pady=2)

    def getcount(self):
        while True:
            try:
                sqlstr1='select count(*) from houtai_alg where isDownloadBg=1'
                rs1=self.ms.ExecQuery(sqlstr1)
                self.countStr.set(f'店铺一共 {rs1[0][0]} 个')
                sqlstr2='select [state],[tcount] from task where [id]=?'
                rs2=self.ms.ExecQuery(sqlstr2,(self.taskid,))
                rwstatus,rwcount=rs2[0]
                if rwstatus==0:
                    self.statusStr.set('任务未开启')
                    self.btn_start.config(state=NORMAL)
                else:
                    self.statusStr.set(f'任务进行中,队列数剩余:{rwcount}')
                    self.btn_start.config(state=DISABLED)

            except Exception as e:
                pass
            time.sleep(5)
    
    def start_task(self):

        if not messagebox.askyesno('提示','确定开启下载波兰跟卖报告任务?'):
            return
        
        self.btn_start.config(state=DISABLED)
        sqlstr1='select count(*) from houtai_alg where isDownloadBg=1'
        rs1=self.ms.ExecQuery(sqlstr1)
        dpcount=rs1[0][0]
        self.countStr.set(f'店铺一共 {dpcount} 个')
        
        aff1=self.ms.ExecNoQuery('update [task] set state=1,tcount=? where [id]=?',(dpcount,self.taskid))
        if aff1:
            print(f'开启任务成功,开始 {dpcount} 个下载波兰跟卖报告')

        else:
            print('开启任务失败')
            messagebox.showerror('提示','开启任务失败')
        
        self.btn_start.config(state=NORMAL)

class PolCJLL(Frame):
    def __init__(self,master=None):
        Frame.__init__(self,master)
        self.ms = sqlseverDB('{SQL Server}', SQL_SERVER, 'SuMaiTongPol', SQL_USER, SQL_PWD)
        self.countStr=StringVar()
        self.countStr.set('正在获取采集波兰产品流量店铺数量...')
        self.statusStr=StringVar()
        self.statusStr.set('正在获取采集波兰产品流量表任务状态')
        self.taskid=20
        self.createWidgets()
        Thread(target=self.getcount).start()

    def createWidgets(self):

        f1=Frame(self)
        f1.pack(fill=X,padx=2,pady=2)

        Lf=Frame(f1)
        Lf.pack(side=LEFT,fill=Y)

        
        f03=Frame(Lf)
        f03.pack(fill=X,padx=2)
        Label(f03, text='《采集波兰产品流量》',fg='#6B238E',font=("微软雅黑", 12),anchor="w").pack(side=LEFT,padx=2)

        f00=Frame(Lf)
        f00.pack(fill=X,padx=2,pady=2)
        Label(f00, textvariable=self.countStr,fg='red').pack(side=LEFT, padx=2, pady=2)
        f02=Frame(Lf)
        f02.pack(fill=X,padx=2,pady=2)
        Label(f02, textvariable=self.statusStr,fg='red',width=30,anchor="w").pack(side=LEFT, padx=2, pady=2)
        f01=Frame(Lf)
        f01.pack(fill=X,padx=2,pady=2)
        self.btn_start=Button(f01,text='开启任务',state=DISABLED,command=lambda:Thread(target=self.start_task).start(),fg='#ffffff',bg='green',width=15)
        self.btn_start.pack(side=LEFT,padx=2, pady=2)

    def getcount(self):
        while True:
            try:
                sqlstr1='select count(*) from houtai_alg where isCjll=1'
                rs1=self.ms.ExecQuery(sqlstr1)
                self.countStr.set(f'店铺一共 {rs1[0][0]} 个')
                sqlstr2='select [state],[tcount] from task where [id]=?'
                rs2=self.ms.ExecQuery(sqlstr2,(self.taskid,))
                rwstatus,rwcount=rs2[0]
                if rwstatus==0:
                    self.statusStr.set('任务未开启')
                    self.btn_start.config(state=NORMAL)
                else:
                    self.statusStr.set(f'任务进行中,队列数剩余:{rwcount}')
                    self.btn_start.config(state=DISABLED)

            except Exception as e:
                pass
            time.sleep(5)
    
    def start_task(self):

        if not messagebox.askyesno('提示','确定开启采集波兰产品流量任务?'):
            return
        
        self.btn_start.config(state=DISABLED)
        sqlstr1='select count(*) from houtai_alg where isCjll=1'
        rs1=self.ms.ExecQuery(sqlstr1)
        dpcount=rs1[0][0]
        self.countStr.set(f'采集波兰产品流量店铺一共 {dpcount} 个')
        
        aff1=self.ms.ExecNoQuery('update [task] set state=1,tcount=? where [id]=?',(dpcount,self.taskid))
        if aff1:
            print(f'开启任务成功,开始 {dpcount} 个采集波兰产品流量')

        else:
            print('开启任务失败')
            messagebox.showerror('提示','开启任务失败')
        
        self.btn_start.config(state=NORMAL)

class PolEndPro(Frame):
    def __init__(self,master=None):
        Frame.__init__(self,master)
        self.ms = sqlseverDB('{SQL Server}', SQL_SERVER, 'SuMaiTongPol', SQL_USER, SQL_PWD)
        self.countStr=StringVar()
        self.countStr.set('正在获取下架跟卖产品店铺数量...')
        self.statusStr=StringVar()
        self.statusStr.set('正在获取下架跟卖产品表任务状态')
        self.taskid=21
        self.createWidgets()
        Thread(target=self.getcount).start()

    def createWidgets(self):

        f1=Frame(self)
        f1.pack(fill=X,padx=2,pady=2)

        Lf=Frame(f1)
        Lf.pack(side=LEFT,fill=Y)

        f03=Frame(Lf)
        f03.pack(fill=X,padx=2)
        Label(f03, text='《下架跟卖产品》',fg='#6B238E',font=("微软雅黑", 12),anchor="w").pack(side=LEFT,padx=2)

        f00=Frame(Lf)
        f00.pack(fill=X,padx=2,pady=2)
        Label(f00, textvariable=self.countStr,fg='red').pack(side=LEFT, padx=2, pady=2)
        f02=Frame(Lf)
        f02.pack(fill=X,padx=2,pady=2)
        Label(f02, textvariable=self.statusStr,fg='red',width=30,anchor="w").pack(side=LEFT, padx=2, pady=2)
        f01=Frame(Lf)
        f01.pack(fill=X,padx=2,pady=2)
        self.btn_start=Button(f01,text='开启任务',state=DISABLED,command=lambda:Thread(target=self.start_task).start(),fg='#ffffff',bg='green',width=15)
        self.btn_start.pack(side=LEFT,padx=2, pady=2)

    def getcount(self):
        while True:
            try:
                sqlstr1='select count(*) from houtai_alg where isEnd=1'
                rs1=self.ms.ExecQuery(sqlstr1)
                self.countStr.set(f'店铺一共 {rs1[0][0]} 个')
                sqlstr2='select [state],[tcount] from task where [id]=?'
                rs2=self.ms.ExecQuery(sqlstr2,(self.taskid,))
                rwstatus,rwcount=rs2[0]
                if rwstatus==0:
                    self.statusStr.set('任务未开启')
                    self.btn_start.config(state=NORMAL)
                else:
                    self.statusStr.set(f'任务进行中,队列数剩余:{rwcount}')
                    self.btn_start.config(state=DISABLED)

            except Exception as e:
                pass
            time.sleep(5)
    
    def start_task(self):

        if not messagebox.askyesno('提示','确定开启下架跟卖产品任务?'):
            return
        
        self.btn_start.config(state=DISABLED)
        sqlstr1='select count(*) from houtai_alg where isEnd=1'
        rs1=self.ms.ExecQuery(sqlstr1)
        dpcount=rs1[0][0]
        self.countStr.set(f'下架跟卖产品店铺一共 {dpcount} 个')
        
        aff1=self.ms.ExecNoQuery('update [task] set state=1,tcount=? where [id]=?',(dpcount,self.taskid))
        if aff1:
            print(f'开启任务成功,开始 {dpcount} 个下架跟卖产品')

        else:
            print('开启任务失败')
            messagebox.showerror('提示','开启任务失败')
        
        self.btn_start.config(state=NORMAL)

class PolRelistPro(Frame):
    def __init__(self,master=None):
        Frame.__init__(self,master)
        self.ms = sqlseverDB('{SQL Server}', SQL_SERVER, 'SuMaiTongPol', SQL_USER, SQL_PWD)
        self.countStr=StringVar()
        self.countStr.set('正在获取上架跟卖产品店铺数量...')
        self.statusStr=StringVar()
        self.statusStr.set('正在获取上架跟卖产品任务状态')
        self.taskid=22
        self.createWidgets()
        Thread(target=self.getcount).start()

    def createWidgets(self):

        f1=Frame(self)
        f1.pack(fill=X,padx=2,pady=2)

        Lf=Frame(f1)
        Lf.pack(side=LEFT,fill=Y)

        
        f03=Frame(Lf)
        f03.pack(fill=X,padx=2)
        Label(f03, text='《上架跟卖产品》',fg='#6B238E',font=("微软雅黑", 12),anchor="w").pack(side=LEFT,padx=2)

        f00=Frame(Lf)
        f00.pack(fill=X,padx=2,pady=2)
        Label(f00, textvariable=self.countStr,fg='red').pack(side=LEFT, padx=2, pady=2)
        f02=Frame(Lf)
        f02.pack(fill=X,padx=2,pady=2)
        Label(f02, textvariable=self.statusStr,fg='red',width=30,anchor="w").pack(side=LEFT, padx=2, pady=2)
        f01=Frame(Lf)
        f01.pack(fill=X,padx=2,pady=2)
        self.btn_start=Button(f01,text='开启任务',state=DISABLED,command=lambda:Thread(target=self.start_task).start(),fg='#ffffff',bg='green',width=15)
        self.btn_start.pack(side=LEFT,padx=2, pady=2)

    def getcount(self):
        while True:
            try:
                sqlstr1='select count(*) from houtai_alg where isActive=1'
                rs1=self.ms.ExecQuery(sqlstr1)
                self.countStr.set(f'店铺一共 {rs1[0][0]} 个')
                sqlstr2='select [state],[tcount] from task where [id]=?'
                rs2=self.ms.ExecQuery(sqlstr2,(self.taskid,))
                rwstatus,rwcount=rs2[0]
                if rwstatus==0:
                    self.statusStr.set('任务未开启')
                    self.btn_start.config(state=NORMAL)
                else:
                    self.statusStr.set(f'任务进行中,队列数剩余:{rwcount}')
                    self.btn_start.config(state=DISABLED)

            except Exception as e:
                pass
            time.sleep(5)
    
    def start_task(self):

        if not messagebox.askyesno('提示','确定开启上架跟卖产品任务?'):
            return
        
        self.btn_start.config(state=DISABLED)
        sqlstr1='select count(*) from houtai_alg where isActive=1'
        rs1=self.ms.ExecQuery(sqlstr1)
        dpcount=rs1[0][0]
        self.countStr.set(f'店铺一共 {dpcount} 个')
        
        aff1=self.ms.ExecNoQuery('update [task] set state=1,tcount=? where [id]=?',(dpcount,self.taskid))
        if aff1:
            print(f'开启任务成功,开始 {dpcount} 个上架跟卖产品')

        else:
            print('开启任务失败')
            messagebox.showerror('提示','开启任务失败')
        
        self.btn_start.config(state=NORMAL)

class PolCJPay(Frame):
    def __init__(self,master=None):
        Frame.__init__(self,master)
        self.ms = sqlseverDB('{SQL Server}', SQL_SERVER, 'SuMaiTongPol', SQL_USER, SQL_PWD)
        self.countStr=StringVar()
        self.countStr.set('正在获取波兰采集付费链接店铺数量...')
        self.statusStr=StringVar()
        self.statusStr.set('正在获取波兰采集付费链接表任务状态')
        self.taskid=23
        self.createWidgets()
        Thread(target=self.getcount).start()

    def createWidgets(self):

        f1=Frame(self)
        f1.pack(fill=X,padx=2,pady=2)

        Lf=Frame(f1)
        Lf.pack(side=LEFT,fill=Y)

        f03=Frame(Lf)
        f03.pack(fill=X,padx=2)
        Label(f03, text='《采集付费链接》',fg='#6B238E',font=("微软雅黑", 12),anchor="w").pack(side=LEFT,padx=2)

        f00=Frame(Lf)
        f00.pack(fill=X,padx=2,pady=2)
        Label(f00, textvariable=self.countStr,fg='red').pack(side=LEFT, padx=2, pady=2)
        f02=Frame(Lf)
        f02.pack(fill=X,padx=2,pady=2)
        Label(f02, textvariable=self.statusStr,fg='red',width=30,anchor="w").pack(side=LEFT, padx=2, pady=2)
        f01=Frame(Lf)
        f01.pack(fill=X,padx=2,pady=2)
        self.btn_start=Button(f01,text='开启任务',state=DISABLED,command=lambda:Thread(target=self.start_task).start(),fg='#ffffff',bg='green',width=15)
        self.btn_start.pack(side=LEFT,padx=2, pady=2)

    def getcount(self):
        while True:
            try:
                sqlstr1='select count(*) from houtai_alg where isCJPay=1'
                rs1=self.ms.ExecQuery(sqlstr1)
                self.countStr.set(f'店铺一共 {rs1[0][0]} 个')
                sqlstr2='select [state],[tcount] from task where [id]=?'
                rs2=self.ms.ExecQuery(sqlstr2,(self.taskid,))
                rwstatus,rwcount=rs2[0]
                if rwstatus==0:
                    self.statusStr.set('任务未开启')
                    self.btn_start.config(state=NORMAL)
                else:
                    self.statusStr.set(f'任务进行中,队列数剩余:{rwcount}')
                    self.btn_start.config(state=DISABLED)

            except Exception as e:
                pass
            time.sleep(5)
    
    def start_task(self):

        if not messagebox.askyesno('提示','确定开启波兰采集付费链接任务?'):
            return
        
        self.btn_start.config(state=DISABLED)
        sqlstr1='select count(*) from houtai_alg where isCJPay=1'
        rs1=self.ms.ExecQuery(sqlstr1)
        dpcount=rs1[0][0]
        self.countStr.set(f'店铺一共 {dpcount} 个')
        
        aff1=self.ms.ExecNoQuery('update [task] set state=1,tcount=? where [id]=?',(dpcount,self.taskid))
        if aff1:
            print(f'开启任务成功,开始 {dpcount} 个波兰采集付费链接')

        else:
            print('开启任务失败')
            messagebox.showerror('提示','开启任务失败')
        
        self.btn_start.config(state=NORMAL)

class PolHidePro(Frame):
    def __init__(self,master=None):
        Frame.__init__(self,master)
        self.ms = sqlseverDB('{SQL Server}', SQL_SERVER, 'SuMaiTongPol', SQL_USER, SQL_PWD)
        self.countStr=StringVar()
        self.countStr.set('正在获取付费链接下架店铺数量...')
        self.statusStr=StringVar()
        self.statusStr.set('正在获取付费链接下架表任务状态')
        self.taskid=24
        self.createWidgets()
        Thread(target=self.getcount).start()

    def createWidgets(self):

        f1=Frame(self)
        f1.pack(fill=X,padx=2,pady=2)

        Lf=Frame(f1)
        Lf.pack(side=LEFT,fill=Y)

        
        f03=Frame(Lf)
        f03.pack(fill=X,padx=2)
        Label(f03, text='《付费链接下架》',fg='#6B238E',font=("微软雅黑", 12),anchor="w").pack(side=LEFT,padx=2)

        f00=Frame(Lf)
        f00.pack(fill=X,padx=2,pady=2)
        Label(f00, textvariable=self.countStr,fg='red').pack(side=LEFT, padx=2, pady=2)
        f02=Frame(Lf)
        f02.pack(fill=X,padx=2,pady=2)
        Label(f02, textvariable=self.statusStr,fg='red',width=30,anchor="w").pack(side=LEFT, padx=2, pady=2)
        f01=Frame(Lf)
        f01.pack(fill=X,padx=2,pady=2)
        self.btn_start=Button(f01,text='开启任务',state=DISABLED,command=lambda:Thread(target=self.start_task).start(),fg='#ffffff',bg='green',width=15)
        self.btn_start.pack(side=LEFT,padx=2, pady=2)

        Lf2=Frame(f1)
        Lf2.pack(side=LEFT,fill=Y)
        PolChangePrice(Lf2).pack(padx=40)

    def getcount(self):
        while True:
            try:
                sqlstr1='select count(*) from houtai_alg where browserid in (select distinct bid from AlOperation where state=0)'
                rs1=self.ms.ExecQuery(sqlstr1)
                self.countStr.set(f'付费链接下架店铺一共 {rs1[0][0]} 个')
                sqlstr2='select [state],[tcount] from task where [id]=?'
                rs2=self.ms.ExecQuery(sqlstr2,(self.taskid,))
                rwstatus,rwcount=rs2[0]
                if rwstatus==0:
                    self.statusStr.set('任务未开启')
                    self.btn_start.config(state=NORMAL)
                else:
                    self.statusStr.set(f'任务进行中,队列数剩余:{rwcount}')
                    self.btn_start.config(state=DISABLED)

            except Exception as e:
                pass
            time.sleep(5)
    
    def start_task(self):

        if not messagebox.askyesno('提示','确定开启付费链接下架任务?'):
            return
        
        self.btn_start.config(state=DISABLED)
        sqlstr1='select count(*) from houtai_alg where browserid in (select distinct bid from AlOperation where state=0)'
        rs1=self.ms.ExecQuery(sqlstr1)
        dpcount=rs1[0][0]
        self.countStr.set(f'店铺一共 {dpcount} 个')
        
        aff1=self.ms.ExecNoQuery('update [task] set state=1,tcount=? where [id]=?',(dpcount,self.taskid))
        if aff1:
            print(f'开启任务成功,开始 {dpcount} 个付费链接下架')

        else:
            print('开启任务失败')
            messagebox.showerror('提示','开启任务失败')
        
        self.btn_start.config(state=NORMAL)

class PolChangePrice(Frame):
    def __init__(self,master=None):
        Frame.__init__(self,master)
        self.ms = sqlseverDB('{SQL Server}', SQL_SERVER, 'SuMaiTongPol', SQL_USER, SQL_PWD)
        self.countStr=StringVar()
        self.countStr.set('正在获取修改产品价格店铺数量...')
        self.statusStr=StringVar()
        self.statusStr.set('正在获取修改产品价格表任务状态')
        self.taskid=29
        self.createWidgets()
        Thread(target=self.getcount).start()

    def createWidgets(self):

        f1=Frame(self)
        f1.pack(fill=X,padx=2,pady=2)

        
        f03=Frame(f1)
        f03.pack(fill=X,padx=2)
        Label(f03, text='《修改产品价格》',fg='#6B238E',font=("微软雅黑", 12),anchor="w").pack(side=LEFT,padx=2)

        f00=Frame(f1)
        f00.pack(fill=X,padx=2,pady=2)
        Label(f00, textvariable=self.countStr,fg='red').pack(side=LEFT, padx=2, pady=2)
        f02=Frame(f1)
        f02.pack(fill=X,padx=2,pady=2)
        Label(f02, textvariable=self.statusStr,fg='red',width=30,anchor="w").pack(side=LEFT, padx=2, pady=2)
        f01=Frame(f1)
        f01.pack(fill=X,padx=2,pady=2)
        self.btn_start=Button(f01,text='开启任务',state=DISABLED,command=lambda:Thread(target=self.start_task).start(),fg='#ffffff',bg='green',width=15)
        self.btn_start.pack(side=LEFT,padx=2, pady=2)

    def getcount(self):
        while True:
            try:
                sqlstr1='''SELECT count(*)
                    FROM houtai_alg AS h
                    JOIN (
                        SELECT DISTINCT a.bid
                        FROM AllGM AS a
                        JOIN ALLGoodPro AS g
                            ON a.pean = g.pean
                        WHERE g.isUpdatePrice = 1
                        AND g.shenhetiji = 1
                        AND g.Y_1688url IS NOT NULL
                        AND a.GMStatus = 1
                        AND a.bid IS NOT NULL
                        and a.priceChanged=0
                    ) AS filtered_bids
                    ON h.browserid = filtered_bids.bid where h.sjbm!='封'
'''
                rs1=self.ms.ExecQuery(sqlstr1)
                self.countStr.set(f'修改产品价格店铺一共 {rs1[0][0]} 个')
                sqlstr2='select [state],[tcount] from task where [id]=?'
                rs2=self.ms.ExecQuery(sqlstr2,(self.taskid,))
                rwstatus,rwcount=rs2[0]
                if rwstatus==0:
                    self.statusStr.set('任务未开启')
                    self.btn_start.config(state=NORMAL)
                else:
                    self.statusStr.set(f'任务进行中,队列数剩余:{rwcount}')
                    self.btn_start.config(state=DISABLED)

            except Exception as e:
                pass
            time.sleep(5)
    
    def start_task(self):

        if not messagebox.askyesno('提示','确定开启修改产品价格任务?'):
            return
        
        self.btn_start.config(state=DISABLED)
        sqlstr1='''SELECT count(*)
                    FROM houtai_alg AS h
                    JOIN (
                        SELECT DISTINCT a.bid
                        FROM AllGM AS a
                        JOIN ALLGoodPro AS g
                            ON a.pean = g.pean
                        WHERE g.isUpdatePrice = 1
                        AND g.shenhetiji = 1
                        AND g.Y_1688url IS NOT NULL
                        AND a.GMStatus = 1
                        AND a.bid IS NOT NULL
                        and a.priceChanged=0
                    ) AS filtered_bids
                    ON h.browserid = filtered_bids.bid where h.sjbm!='封' 
                    '''
        rs1=self.ms.ExecQuery(sqlstr1)
        dpcount=rs1[0][0]
        self.countStr.set(f'店铺一共 {dpcount} 个')
        
        aff1=self.ms.ExecNoQuery('update [task] set state=1,tcount=? where [id]=?',(dpcount,self.taskid))
        if aff1:
            print(f'开启任务成功,开始 {dpcount} 个修改产品价格')

        else:
            print('开启任务失败')
            messagebox.showerror('提示','开启任务失败')
        
        self.btn_start.config(state=NORMAL)


# import tkinter
# list_win=tkinter.Tk()
# list_win.wm_geometry("800x650")
# list_win.title('AlgQKFra')
# AlgQKFra(list_win).pack(fill=X,padx=3,pady=3)
# list_win.mainloop()